package com.mxin.mvvm.viewmodel

import androidx.lifecycle.ViewModel
import com.mxin.common.ui.livedata.SingleLiveEvent

open class BaseViewModel : ViewModel() {

    val uiLiveEvent by lazy { UILiveData() }

    class UILiveData : SingleLiveEvent<Void>(){

        //数据加载Dialog的显示
        val showLoadingViewEvent by lazy { createLiveData<Boolean>(null) }

    }


    companion object{

        inline fun <reified T> createLiveData(liveData: SingleLiveEvent<T>?): SingleLiveEvent<T>? {
            var liveData: SingleLiveEvent<T>? = liveData
            if (liveData == null) {
                liveData = SingleLiveEvent()
            }
            return liveData
        }

    }
}